package com.wyl.jetpack

import android.os.Bundle
import android.util.Log
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.wyl.baselib.base.BaseActivity
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel

class MainActivity : BaseActivity() {
    private val navController by lazy { findNavController(R.id.fragment) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

//        setupActionBarWithNavController(navController)

        val conf = AppBarConfiguration(navController.graph)
        setupActionBarWithNavController(navController, conf)

        toolbar.setupWithNavController(navController)

        navController.addOnDestinationChangedListener { _, destination, arguments ->
            Log.d("ddd", "destination = $destination")
            Log.d("ddd", "arguments = $arguments")
        }
    }

    override fun onSupportNavigateUp(): Boolean =
        navController.navigateUp() || super.onSupportNavigateUp()

}
